//
//  SolutionNode.m
//  PentahoIConsole
//
//  Created by Bill Seyler on 6/10/10.
//  Copyright 2010 Pentaho Corporation. All rights reserved.
//

#import "SolutionNode.h"


@implementation SolutionNode

@synthesize repository_path;

@synthesize fileName;
@synthesize localized_name;
@synthesize description;
@synthesize url;
@synthesize parameter_service_url;
@synthesize directory;
@synthesize visible;

@synthesize parent;
@synthesize children;

- (id) init 
{ 
	if ( self = [super init] ) { 
		children = [[NSMutableArray alloc] init]; 
	} 
	return self; 
} 

- (void)dealloc
{
	[fileName release];
	[localized_name release];
	[description release];
	[url release];
	[parameter_service_url release];
	
	[parent release];
	[children release];
	
	[super dealloc];
}

- (void) addChild:(SolutionNode*) node 
{
	[children addObject:node];
}

- (void) removeChild:(SolutionNode*) node
{
	[children removeObjectAtIndex:[children indexOfObject:node]];
}

- (NSString *)solution
{
	SolutionNode *currentNode = self;
	while ([[currentNode parent] parent]) {
		currentNode = [currentNode parent];
	}
	return [currentNode fileName];
}

- (NSString *)path
{	
	SolutionNode *currentNode = parent;
	NSString *pathStr = [NSString stringWithFormat:@"%@", [currentNode fileName]];
	while ([[[currentNode parent] parent] parent]) {
		currentNode = [currentNode parent];
		pathStr = [NSString stringWithFormat:@"%@/%@", [currentNode fileName], pathStr];
	}
	return pathStr;
}
@end
